package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.SysArea;
import com.ruoyi.system.service.ISysAreaService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/area")
public class SysAreaController {
    @Autowired
    private ISysAreaService areaService;

    @RequestMapping(value = "/selectProvince",method = RequestMethod.GET)
    public AjaxResult selectProvince() {
        QueryWrapper<SysArea> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SysArea::getDeep,0);
        List<SysArea> list = areaService.list(wrapper);
        return AjaxResult.success(list);
    }

    @RequestMapping(value = "/selectCity",method = RequestMethod.GET)
    public AjaxResult selectCity(@RequestParam("pid")Long pid,
                                 @RequestParam("deep") Integer deep) {
        QueryWrapper<SysArea> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(SysArea::getPid,pid).eq(SysArea::getDeep, deep);
        List<SysArea> list = areaService.list(wrapper);
        return AjaxResult.success(list);
    }

}
